﻿namespace _121买卖股票的最佳时机
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
        }
    }
    public class Solution
    {
        public int MaxProfit(int[] prices)
        {
            int maxprofit = 0;
            int minPrice = int.MaxValue;
            for (int i = 0; i < prices.Length; i++)
            {
                if (prices[i] < minPrice)
                {
                    minPrice = prices[i];
                }
                if (prices[i]- minPrice > maxprofit)
                {
                    maxprofit = prices[i] - minPrice;
                }
            }
            return maxprofit;
        }
    }
}